
//% color="#ff6b81" iconWidth=50 iconHeight=40
namespace Pandas{

    //% block="初始化Pandas模块" blockType="command"
    export function Pandas_init(parameter: any, block: any) {
        Generator.addImport(`import pandas as pd`)
        
    }
    //% block="设置显示格式[TYPE]参数[NUM]" blockType="command"
    //% TYPE.shadow="string" TYPE.defl="display.unicode.east_asian_width"
    //% NUM.shadow="normal" NUM.defl="True"
    export function Pandas_inittype(parameter: any, block: any) {
        let type=parameter.TYPE.code;
        let num=parameter.NUM.code;              
        Generator.addCode(`pd.set_option(${type},${num})`) 
    }
    //% block="对象名[OBJECT]读取CSV文件[CSV]" blockType="command"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% CSV.shadow="string" CSV.defl="data.csv"
    export function Pandas_initread(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let csv=parameter.CSV.code;      
        Generator.addCode(`${obj} = pd.read_csv(${csv})`) 
    }

    //% block="对象名[OBJECT]获取[LINE]行数据" blockType="reporter"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% LINE.shadow="normal" LINE.defl="5"
    export function Pandas_initreadline(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let line=parameter.LINE.code;      
        Generator.addCode(`${obj}.head(${line})`)  
    }
    //% block="对象名[OBJECT]获取标题行[STR]的整列中[VALVE]属性的数据" blockType="reporter"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% STR.shadow="string" STR.defl="工作时段"
    //% VALVE.shadow="dropdown" VALVE.options="VALVE"
    export function Pandas_initlowvalues(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let str=parameter.STR.code;
        let valve=parameter.VALVE.code;
        if(`${valve}` === '1'){
            Generator.addCode(`${obj}[${str}]`) 
        }else{
            Generator.addCode(`${obj}[${str}].values `) 
        }
    }
    //% block="对象名[OBJECT]删除标题行[STR]的整列" blockType="reporter"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% STR.shadow="string" STR.defl="序号"
    export function Pandas_initreadline1(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let str=parameter.STR.code;
        Generator.addCode(`${obj}.drop(${str},axis = 1)`) 
    }

    //% block="对象名[OBJECT]将保存CSV文件[STR]以[TYPE]索引方式" blockType="command"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% TYPE.shadow="dropdown" TYPE.options="TYPE"
    //% STR.shadow="string" STR.defl="data.csv"
    export function Pandas_initsave(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let type=parameter.TYPE.code;
        let str=parameter.STR.code;
        Generator.addCode(`${obj}.to_csv(${str},index = ${type})`) 
    }

    //% block="对象名[OBJECT]指定标题行[STR]的数据[DATA]替换为[FLAG]" blockType="command"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% STR.shadow="string" STR.defl="工作时段"
    //% DATA.shadow="list" DATA.defl="'早晨','中午','下午','傍晚'"
    //% FLAG.shadow="string" FLAG.defl="工作时间段"
    export function Pandas_initdata(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let str=parameter.STR.code;
        let data=parameter.DATA.code;
        let flag=parameter.FLAG.code;
        Generator.addCode(`${obj}[${str}] = ${obj}[${str}].replace(${data},${flag})`) 
    }

    //% block="对象名[OBJECT]指定标题行[STR]的整列数据替换为编码数据[VALUES]" blockType="command"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% STR.shadow="string" STR.defl="工作时段"
    //% VALUES.shadow="normal" VALUES.defl="[0 1]"
    export function Pandas_initvalues1(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let str=parameter.STR.code;
        let values=parameter.VALUES.code;
 
        Generator.addCode(`${obj}[${str}] = ${values}`) 
    }

    //% block="---"
    export function noteSep1() {
    }
    //% block="对象名[OBJECT]使用[MERHOD]方法获取相关系数" blockType="reporter"
    //% OBJECT.shadow="normal" OBJECT.defl="HAR_df"
    //% MERHOD.shadow="normal" MERHOD.defl="pearson"
    export function Pandas_initscreendata1(parameter: any, block: any) {
        let obj=parameter.OBJECT.code;
        let method=parameter.MERHOD.code;
        Generator.addCode(`${obj}.corr(method='${method}')`) 
    }  
}


